/**
 * 所有版权归 广西梧州 陈锦韬 所有
 *
 * @Title: SingleDetailHandler
 * @Package com.rx.uua.handler
 * @Description: 详情处理器
 * @author: 陈锦韬
 * @date: 2021\6\11 0011
 * @version V1.0
 * @Copyright: 2021 陈锦韬  All rights reserved.
 */
package com.rx.uua.handler;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rx.core.base.RxBaseData;
import com.rx.core.base.RxResponse;
import com.rx.core.dbase.RxBaseDbMust;
import com.rx.core.enm.HANDLER_TYPE;
import com.rx.core.handler.RxHandler;
import com.rx.core.handler.RxHandlerAfter;
import com.rx.core.handler.RxHandlerContent;
import com.rx.core.handler.RxHandlerPrev;
import com.rx.core.service.StandardService;
import com.rx.uua.dao.PlfUserInfoMapper;
import com.rx.uua.dao.UuaUserInfoMapper;
import com.rx.uua.vo.PlfUserInfo;
import com.rx.uua.vo.UuaUserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;
import java.util.List;

/**
 * @author: Administrator
 * @Description: 详情处理器
 * @date: 2021\6\11 0011
 */
@RxHandler
@Slf4j
public class SingleDetailHandler implements RxHandlerContent {

    @Autowired
    UuaUserInfoMapper mapper;


    @Autowired
    StandardService standardService;

    @RxHandlerPrev
    public boolean prehandle(RxBaseData data){
        log.info("操作前");
//        RxBaseData condition = new PlfUserInfo();
//        condition.setUrlAnalyse(UrlAnalyse.create("/rx-standard-api/single/plf-user-info/standard/search-list"));
//        condition.setHandlerController(RxHandlerController.create()
//                .removePrev("prehandle3")
//                .appendPrev("prehandle3",3)
//                .appendAfter("com.rx.uua.handler.SingleListHandler.afterhandle",3));

        try {
            RxBaseData condition = RxBaseData.create(PlfUserInfo.class,HANDLER_TYPE.SINGLE_LIST);
            condition.getHandlerController()
                    .appendPrev("prehandle",2)
                    .appendPrev("prehandle3",3)
                    .appendAfter("com.rx.uua.handler.SingleListHandler.afterhandle",3);

            log.info("类" + condition.getClass().getSimpleName());
            Object object = standardService.searchList(condition);
            if(object instanceof RxResponse){
                data.setResultMessage("列表返回数据为空");
               return false;
            }
            List<UuaUserInfo> resultList = (List<UuaUserInfo>)object;
            for (UuaUserInfo plfUserInfo : resultList) {
                log.info("项："+plfUserInfo.getRealName());
            }
        } catch (IllegalAccessException | InstantiationException e) {

        }

        return false;
    }
    @RxHandlerPrev(types= {HANDLER_TYPE.SINGLE_DETAIL},order = 2,keys = {})
    public boolean prehandle2(RxBaseData data){
        log.info("操作前2");
        return false;
    }
    @RxHandlerPrev(order = 2,
    keys={"api/ur2","api/uew3","api/uew3e"})
    @RxHandlerAfter(types= {HANDLER_TYPE.SINGLE_DETAIL})
    public boolean prehandle3(RxBaseData data){
        log.info("操作前1");
        return false;
    }
    @RxHandlerAfter(types= {HANDLER_TYPE.SINGLE_DETAIL})
    public boolean afterhandle(RxBaseData data){
        log.info("操作后");
        return false;
    }

    @RxHandler(types= {HANDLER_TYPE.SINGLE_DETAIL})
    public boolean over(RxBaseData data){
        log.info("覆盖");
        QueryWrapper queryWrapper = new QueryWrapper<>();
        RxBaseDbMust rxBaseDbMust = (RxBaseDbMust)data;
        queryWrapper.eq("bid",rxBaseDbMust.getBid());
        queryWrapper.in("valid", Arrays.asList(1,2));

        RxBaseData result = (RxBaseData)mapper.selectOne(queryWrapper);
        data.setResultData(result);
        return false;
    }

    @Override
    public boolean handle(RxBaseData data) {
        log.info("接口处理器");
        return false;
    }
}
